#include <bits/stdc++.h>
using namespace std;

int n, m, v[1501];
string s;
string ans;
string t[1506];
long double a = 1;

inline void dfs(int i, long double res, int tot) {
	if (i == n) {
		if (tot == 0) return;
		if (powl(res, (long double)1.0f / tot) >= a) {
			a = powl(res, (long double)1.0f / tot);
			ans = s;
		}
		return;
	}
	if (s[i] == '.') {
		for (int j = 0; j <= 9; ++j) {
			s[i] = j + '0';
			long double tres = res, ttot = tot;
			for (int k = 1; k <= m; ++k) {
				if (i >= t[k].size())
					if (s.substr(i - t[k].size(), t[k].size()) == t[k]) tres *= v[k], ++ttot;
			}
			dfs(i + 1, tres, ttot);
			s[i] = '.';
		}
	} else {
		long double tres = res, ttot = tot;
		for (int k = 1; k <= m; ++k) {
			if (i >= t[k].size())
				if (s.substr(i - t[k].size(), t[k].size()) == t[k]) tres *= v[k], ++ttot;
		}
		dfs(i + 1, tres, ttot);
	}
	
}

int main() {
	freopen("magic.in", "r", stdin);
	freopen("magic.out", "w", stdout);
	scanf("%d%d", &n, &m);
	cin >> s;
	for (int i = 1; i <= m; ++i) {
		cin >> t[i] >> v[i];
	}
	dfs(0, 1, 0);
	cout << ans << endl;
}
